<?php
$page_title="Manage Event Invitations ";
include("includes/header.php");

$list_id=(int)$_GET["list_id"];
if($list_id==0){
	$prg_id=(int)$_GET["prg_id"];
	if($prg_id>0){
	$invlist_info=@array_pop(qry_data("select list_id  from bkitc_invite_list where list_event_id =".$prg_id));
	
	$list_id=$invlist_info["list_id"];
	}
}
$mode=$_GET["mode"];


if($mode=="edit") 	$invlist_info=@array_pop(qry_data("select * from bkitc_invite_list where list_id=".$list_id));
if($mode=="del"){
	exec_qry("update bkitc_invite_list set rec_status=0 where list_id=".$list_id);//Soft Delete
	header("location:event_inv_list.php");
}
?>				
<div class="fleft">
<ul class="subMenu">
<li><a href="edit_event_inv.php?mode=add">Add New </a></li>
<li><a href="event_inv_list.php?mode=result">Back to List </a></li>
</ul>
</div>
<div class="cleardiv"></div>
	<div style="width:100%" class="content_bg">
	<form method="post" action="edit_event_inv_pro.php?list_id=<?=$list_id?>" > 
		<table class="voip_form" width="600"  cellpadding="8" border="0" cellspacing="3"> 
			<tr>
				<td  height="10" style="padding:2px;margin:2px" colspan="2" align="right"><small style="font-size:11px"> <i><?=ast()?>  Required fields.</i></small></td>
			</tr>
		
			<?$query="select prg_id,prg_title from bkitc_programs where rec_status>=1 ";
			$prgInfo=qry_data($query);

?>
			<tr>
			<td class="frmLabel">Invitation List for Event&nbsp;</td>
			<td>


<?
$prgInfoList=Array();
$prgInfoList[0]="----Select Event----";
foreach($prgInfo as $i=>$prg){
$prgInfoList[$prg["prg_id"]]=$prg["prg_title"];

 }?>


<?=createSelect("list_event_id", $prgInfoList, $invlist_info["list_event_id"],$mode=="edit"?"disabled":"")?> <a href="javascript:location.href='edit_prg.php?mode=edit&prg_id=' + $('list_event_id').value;">Edit this Event Details</a>

</td>
			</tr>
			
			<tr>
			<td class="frmLabel">Invitation List Title&nbsp;</td>
			<td><input type="text" name="list_title" id="list_title" size="90" maxlength="90" value="<?=$invlist_info["list_title"];?>"  type="text" class="txtbox"	 /></td>
			</tr>
			<tr>
				<td class="frmLabel" valign="top" colspan="2"> Description <?=ast()?><br/><br/>
				 <textarea class="txtarea"  id="list_desc" rows="2" cols="50" name="list_desc" style="width:600px;height:60px;"><?=$invlist_info["list_desc"]?></textarea> </td>
			</tr>
			

	
			<tr bgcolor="#fff" style="height:50px;margin:0px;padding:0px;">
				
				<td  style="margin:0px;padding:2px;" align="right" colspan="2">
				<input type="submit" class="button"  value="Save Info">&nbsp;
				<input class="button" type="reset">
				<input onclick="location.href='event_inv_list.php'"  type="button" class="button" value=" Back to  List">
				</td>
			</tr>
			
		</table>
	</form>
</div>

<div style="margin-bottom:40px">
	<hr/>
	<div style="float:left;">
	<h3>Members Added to this List :  </h3>
</div><div>
<div class="stat_legend" style="float:right;">
		<div class="invitem1"></div><label>Invited</label>
		<div class="invitem2"></div><label>Not Invited</label>
		<div class="invitem3"></div><label>Invited and Accepted</label>
		<div class="invitem4"></div><label>Accepted and Cancelled</label>
	</div>
</div>
	
<div style="clear:both">

	</div>
	<? if($mode=="edit") {?>
	<?
	$memInfo=qry_data(
		"
		SELECT  distinct PM.acc_status,I.list_event_id,P.full_name,P.registrant_id,L.inv_status 
		FROM bkitc_invite_list_mem L JOIN bkitc_profiles P on P.registrant_id=L.mem_id 
		JOIN bkitc_invite_list I on I.list_id=L.list_id  LEFT JOIN  bkitc_program_members PM ON PM.member_id=P.registrant_id and PM.program_id=I.list_event_id
		WHERE  I.rec_status=1 and L.list_id=".(int)$list_id);


	foreach($memInfo as $k=>$item){

		$invstatusClass="invitem2";
		if($item["inv_status"]==1) $invstatusClass=" invitem1";
		if($item["acc_status"]==1) $invstatusClass=" invitem3";
		if($item["acc_status"]==2) $invstatusClass=" invitem4";
	?>

	<div style="float:left;width:300px;">
		
		<span class="<?=$invstatusClass?>" style="height:30px;" ><input type="checkbox" class="chk_item" value="<?=$item["registrant_id"]?>" id="mem<?=$item["registrant_id"]?>"  <?=$item["inv_status"]==1?"disabled":""?>    >	</span>
		<label for="mem<?=$item["registrant_id"]?>" > <a href="edit_prg_mem.php?mode=edit&prgId=<?=$item["list_event_id"]?>&mem_id=<?=$item["registrant_id"]?>"><?=$item["full_name"]." - ".formatMemberCode($item["registrant_id"])?></a></label>
	</div>
	<?
	}
?>

	<div style="clear:both">

	</div>

	<div>
	<br/>
		<input class="button" type="button" value="Send Invitation" onclick="inviteMember()"><br/><br/>
		<h4>Download Excel file</h4><br/>
		
		<a class="button" href="export_invite.php?mode=1&list_id=<?=$list_id?>">Members Linked to this List</a><br/><br/>
		<a class="button" href="export_invite.php?mode=2&list_id=<?=$list_id?>">Members Invited List</a><br/><br/>
		<a class="button" href="export_invite.php?mode=3&list_id=<?=$list_id?>">Members Accepted List</a><br/><br/>
		<!--<a class="button" href="export_invite.php?mode=4&list_id=<?=$list_id?>">Acceptance Pending List</a><br/><br/>-->
		<a class="button" href="export_invite.php?mode=5&list_id=<?=$list_id?>">Accepted and Cancelled List</a><br/><br/>

	</div>	
</div>
<? } ?>
<link rel="stylesheet" href="includes/wysiwyg.css" type="text/css">
<script type="text/javascript" src="includes/scripts/wysiwyg.js"></script>
<script type="text/javascript" src="includes/scripts/wysiwyg-settings.js"></script>
		<!-- 
			Attach the editor on the textareas
		-->
		<script type="text/javascript">
		var listId='<?echo $list_id;?>';
		function inviteMember(){
			var vPrgId=$("list_event_id").value;
			
			var strList="";
			$$(".chk_item").each(function(vItem){
				if(vItem.checked){
				 if(strList=="")
					 strList=vItem.value
				 else 
					strList=strList + "," + vItem.value ;
				 }}
				);
				

			if(strList==""){

			alert("Please select atleat 1 member for inviting to the program.");
			$('selPrg').value=0;
			return;
			}	
			if(vPrgId==0) return;	
			if(confirm('Are you sure to invite selected members to this program?')){


			new Ajax.Request("notify_member.php?list_id=" + listId + "&prg_id=" +vPrgId+ "&mv=1&sel="+strList, {
						method: 'get',
						onSuccess: function(req) {
							alert(req.responseText);
							location.reload();
							//onSuccess(req);
						}
					});

			}

			}
			
		</script>

<style>
.invitem1{
background:lightgreen;
padding:3px;
}
.invitem2{
background:orange;
}
 .invitem3{
background:darkgreen;
}
.invitem4{
background:red;
}

.stat_legend div{
width:10px;
height:10px;

padding:1px;
border:1px solid #ccc;
margin-right:4px;
float:left;
}
.stat_legend label{
float:left;
margin-left:4px;
margin-right:4px;
}
</style>
<? include("includes/footer.php");?>
